﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Collections;
using System.Data;

namespace Catering.Catering_Page.system
{
    public partial class ModuleInfo_Manage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.HidCid.Value = Request.QueryString["cid"].ToString();
                this.LoadRep();
            }
        }

        //加载Rep控件
        public void LoadRep()
        {
            string ModuleID = Request.QueryString["cid"].ToString();
            this.AspNetPager1.RecordCount = new Catering_Rules.Module_operating().GetCountBywhere("ModuleID=" + ModuleID);
            DataTable dt_Personnel = new Catering_Rules.Module_operating().GetList(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex - 1, "ModuleID=" + ModuleID).Tables[0];
            this.Rep_Personnel.DataSource = dt_Personnel;
            this.Rep_Personnel.DataBind();
        }

        //分页
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.LoadRep();
        }

        //添加模块
        protected void btn_Add_Click(object sender, EventArgs e)
        {
            Catering_Model.Module_operating md = new Catering_Model.Module_operating();
            md.id = new Catering_Rules.Module_operating().GetMaxId();
            md.Back = this.txt_back.Text.Trim();
            md.operating = this.txt_name.Text.Trim();
            md.ModuleID = Convert.ToInt32(Request.QueryString["cid"].ToString());
            new Catering_Rules.Module_operating().Add(md);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功！')</script>");
            this.LoadRep();
        }

        //修改模块
        protected void btn_Edit_Click(object sender, EventArgs e)
        {
            Catering_Model.Module_operating md = new Catering_Model.Module_operating();
            md.id = Convert.ToInt32(this.HidRid.Value);
            md.Back = this.txt_back.Text.Trim();
            md.operating = this.txt_name.Text.Trim();
            md.ModuleID = Convert.ToInt32(Request.QueryString["cid"].ToString());
            new Catering_Rules.Module_operating().Update(md);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功！')</script>");
            this.LoadRep();
        }

        //删除模块
        [WebMethod]
        public static string DelModule(string uid)
        {
            new Catering_Rules.Module_operating().Delete(Convert.ToInt32(uid));
            return "OK";
        }

        //获取模块信息
        [WebMethod]
        public static ArrayList GetModule(string uid)
        {
            ArrayList al = new ArrayList();
            Catering_Model.Module_operating md = new Catering_Rules.Module_operating().GetModel(Convert.ToInt32(uid));
            al.Add(md.operating);
            al.Add(md.Back);
            return al;
        }
    }
}